//package com.daocao.hua.fragment;
//
//import android.content.Intent;
//import android.graphics.Color;
//import android.graphics.drawable.GradientDrawable;
//import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.support.v7.widget.CardView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.CheckBox;
//import android.widget.FrameLayout;
//import android.widget.LinearLayout;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//
//import com.daocao.hua.R;
//import com.daocao.hua.activity.Application;
//import com.daocao.hua.activity.Idcardv2Activity;
//import com.daocao.hua.activity.MainActivityNew;
//import com.daocao.hua.activity.NewApplyForActivity;
//import com.daocao.hua.activity.SelectMoneyActivity;
//import com.daocao.hua.activity.UserPurposeActivity;
//import com.daocao.hua.activity.V3LoginByCodeActivity;
//import com.daocao.hua.adapter.CardAdapter;
//import com.daocao.hua.api.callback.FragmentSelectMoneyContract;
//import com.daocao.hua.api.requestInfo.FragmentSelectMoneyRequest;
//import com.daocao.hua.constant.Const;
//import com.daocao.hua.constant.UserGlobal;
//import com.daocao.hua.event.OnHomeEventMsg;
//import com.daocao.hua.event.OnSelectMoneyUpdateMsg;
//import com.daocao.hua.model.DealBeforeModel;
//import com.daocao.hua.model.DealTypesModel;
//import com.daocao.hua.model.NewBeginApplyModel;
//import com.daocao.hua.util.DateTime;
//import com.daocao.hua.util.DisplayUtil;
//import com.daocao.hua.util.ImageUtil;
//import com.daocao.hua.util.PreferenceUtils;
//import com.daocao.hua.util.ToastUtil;
//import com.daocao.hua.util.UI;
//import com.daocao.hua.util.Util;
//import com.daocao.hua.view.CircularProgress;
//import com.daocao.hua.view.Dialog;
//
//import org.greenrobot.eventbus.EventBus;
//import org.greenrobot.eventbus.Subscribe;
//import org.greenrobot.eventbus.ThreadMode;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import butterknife.BindView;
//import butterknife.ButterKnife;
//import butterknife.OnClick;
//import butterknife.Unbinder;
//
//
//public class SelectMoneyFragment extends BaseFragment implements FragmentSelectMoneyContract.View {
//
//
//    @BindView(R.id.txt_date)
//    TextView txtDate;
//    @BindView(R.id.txt_get_money)
//    TextView txtGetMoney;
//    @BindView(R.id.txt_repay_money)
//    TextView txtRepayMoney;
//    @BindView(R.id.txt_repay_date)
//    TextView txtRepayDate;
//    Unbinder unbinder;
//    @BindView(R.id.cardView)
//    CardView mCardView;
//    @BindView(R.id.txt_level)
//    TextView txtLevel;
//    @BindView(R.id.txt_tips)
//    TextView txtTips;
//    @BindView(R.id.rl_level)
//    RelativeLayout rlLevel;
//    @BindView(R.id.txt_xinshen_fee)
//    TextView txtXinshenFee;
//    @BindView(R.id.txt_manage_fee)
//    TextView txtManageFee;
//    @BindView(R.id.txt_lixi_fee)
//    TextView txtLixiFee;
//    @BindView(R.id.cb_agree)
//    CheckBox cbAgree;
//    @BindView(R.id.txt_agree)
//    TextView txtAgree;
//    @BindView(R.id.txt_money)
//    TextView txtMoney;
//    @BindView(R.id.progressBar)
//    CircularProgress loading;
//    @BindView(R.id.btn_apply)
//    TextView btnApply;
//    @BindView(R.id.fl_background)
//    FrameLayout flBackground;
//    @BindView(R.id.ll_agree)
//    LinearLayout llAgree;
//    private int poi;
//    private FragmentSelectMoneyRequest api;
//    private String loanTypeId;
//
//
//    @Nullable
//    @Override
//    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
//                             @Nullable Bundle savedInstanceState) {
//        View rootView = super.onCreateView(inflater, container, savedInstanceState);
//        unbinder = ButterKnife.bind(this, rootView);
//        mCardView.setMaxCardElevation(mCardView.getCardElevation()
//                * CardAdapter.MAX_ELEVATION_FACTOR);
//        return rootView;
//    }
//
//    @Override
//    protected int setLayoutId() {
//        return R.layout.fragment_select_money;
//    }
//
//    @Override
//    protected void initView() {
//        api = FragmentSelectMoneyRequest.create();
//        api.attachView(this);
//        EventBus.getDefault().register(this);
//    }
//
//
//    @Override
//    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
//        super.onViewCreated(view, savedInstanceState);
////        UI.setTvHtml(txtAgree, R.string.select_money_agree);
//
//
//        if (item != null) {
////            txtMoney.setText(item.maximum+"元");
//            txtMoney.setText(item.borrow_amount + "元");
//            txtGetMoney.setText(item.give_money + "元");
//            txtDate.setText(item.repaytime + item.repaytime_type);
//            txtRepayDate.setText(DateTime.toMonthDay(item.repay_end_time * 1000));
//            txtRepayMoney.setText(item.repay_money + "元");
////            UI.setTvHtml(txtXinshenFee, R.string.select_money_info, "信用管理费", item.services_detail.fast_audit_fee + "元");
////            UI.setTvHtml(txtManageFee, R.string.select_money_info, "居间服务费", item.services_detail.account_manage_fee + "元");
////            UI.setTvHtml(txtLixiFee, R.string.select_money_info, "利息费", item.services_detail.interests + "元");
//
//
//            setLayoutVisible();
//            try {
//                int colors[] = new int[]{Color.parseColor(item.backgroup_colors.left_top.trim()), Color.parseColor(item.backgroup_colors.right_bottom.trim())};
//                GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TL_BR, colors);
//                g.setCornerRadius(DisplayUtil.dip2px(getContext(), 10));
//                flBackground.setBackgroundDrawable(g);
//
//                txtAgree.setTextColor(Color.parseColor(item.protocol_color));
//            } catch (Exception ex) {
//
//            }
//
//
////            int colorsButton[] = new int[]{Color.parseColor(item.button_colors.left_top.trim()), Color.parseColor(item.button_colors.right_bottom.trim())};
////            GradientDrawable gButton = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colorsButton);
////            gButton.setCornerRadius(DisplayUtil.dip2px(getActivity(), 14));
////            btnApply.setBackgroundDrawable(gButton);
//
//
//        }
//    }
//
//    private void setLayoutVisible() {
//        if (item.limit_user_level == 1 && PreferenceUtils.getInt(Application.getInstance(), Const.KEY.LEVEL, 0) == 0) {
//            if (rlLevel.getVisibility() == View.VISIBLE) {
//                rlLevel.setVisibility(View.GONE);
//            }
//            btnApply.setEnabled(true);
//        } else if (item.limit_user_level > PreferenceUtils.getInt(Application.getInstance(), Const.KEY.LEVEL, 0)) {
//            if (rlLevel.getVisibility() == View.GONE) {
//                rlLevel.setVisibility(View.VISIBLE);
//                txtLevel.setText("LV " + item.limit_user_level + " 开锁");
//            }
//            btnApply.setEnabled(false);
//        } else {
//            if (rlLevel.getVisibility() == View.VISIBLE) {
//                rlLevel.setVisibility(View.GONE);
//            }
//            btnApply.setEnabled(true);
//        }
//    }
//
//    public CardView getCardView() {
//        return mCardView;
//    }
//
//
//    private DealTypesModel.DataBean item;
//
//    public void setData(DealTypesModel.DataBean item) {
////        txtMoney.setText(item.getMaximum() + "元");
////        txtDate.setText(item.getRepaytime() + item.getRepaytime_type());
//        this.item = item;
//        loanTypeId = item.id + "";
//    }
//
//    public void updateData(DealTypesModel.DataBean item) {
////        txtMoney.setText(item.getMaximum() + "元");
////        txtDate.setText(item.getRepaytime() + item.getRepaytime_type());
//        this.item = item;
//        loanTypeId = item.id + "";
////        setLayoutVisible();
//    }
//
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void update(OnSelectMoneyUpdateMsg msg) {
//        setLayoutVisible();
//    }
//
//    @Override
//    public void onDestroyView() {
//        EventBus.getDefault().unregister(this);
//        ImageUtil.releaseImageViewResouce(flBackground);
//        ImageUtil.releaseImageViewResouce(btnApply);
//        api.detachView();
//        api = null;
//        unbinder.unbind();
//        unbinder = null;
//        super.onDestroyView();
//    }
//
//    @Override
//    public void showError() {
//
//    }
//
//    @Override
//    public void complete() {
//        showLoading(false);
//    }
//
//    @Override
//    public void onRequestStart() {
//        showLoading(true);
//    }
//
//    @Override
//    public void getNewBeginApplySuccess(NewBeginApplyModel model) {
////        0：失败
////        1：走新申请流程
////        2：继续上次未完成的流程
////        3：上一次申请审核中
////        4：上一次申请未通过
////        5：上一次申请使用中（未放款）
////        6：上一次申请待还款（已放款）
//        PreferenceUtils.putString(getActivity(), "deal_id", model.deal_id);
//        PreferenceUtils.putInt(getActivity(), "status", model.getStatus());
//
//        switch (model.getStatus()) {
//            case 1:
//            case 2:
//                UserGlobal.info.datas = model.steps;
//                UserGlobal.info.deal_id = model.deal_id;
//                UserGlobal.info.type = 1;
////                Intent intent = new Intent(getActivity(), LoanAgreementActivity.class);
//                Intent intent = new Intent(getActivity(), UserPurposeActivity.class);
//                intent.putExtra("deal_id", model.deal_id);
//                intent.putParcelableArrayListExtra("loan_steps", model.steps);
//                intent.putExtra("type", 1);
//                startActivity(intent);
//                getActivity().overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//                break;
//            case 3:
//            case 4:
//            case 5:
//                Intent intent1 = new Intent(getContext(), NewApplyForActivity.class);
//                startActivity(intent1);
//                getActivity().overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//                getActivity().finish();
//                break;
//            case 6:
//                showRepayDialog(model.getMsg());
//                break;
//        }
//    }
//
//    /**
//     * 显示还钱对话框
//     */
//    private void showRepayDialog(String msg) {
//
//        Dialog.showRepayTipsDialog(getActivity(), msg, new Dialog.DialogDefaultClickListener() {
//            @Override
//            public void confirm() {
//                sendEventBus();
//            }
//
//            @Override
//            public void cancel() {
//
//            }
//        });
//
//    }
//
//    /**
//     * 切换主界面
//     */
//    private void sendEventBus() {
//
//        Map<String, String> map = new HashMap<>();
//        map.put("type", Const.SendType.SWITCH_PAGE);
//        map.put("currentIndex", Const.View.REPAY_VIEW + "");
//        EventBus.getDefault().post(new OnHomeEventMsg(map));
//        Util.startActivity(getActivity(), MainActivityNew.class);
//        getActivity().finish();
//    }
//
//    /**
//     * 是否显示加载框
//     *
//     * @param b
//     */
//    private void showLoading(boolean b) {
//        if (b) {
//            btnApply.setEnabled(false);
//            if (loading != null) loading.setVisibility(View.VISIBLE);
//        } else {
//            btnApply.setEnabled(true);
//            if (loading != null) loading.setVisibility(View.GONE);
//        }
//    }
//
//    @Override
//    public void getDealBeforeSuccess(DealBeforeModel item) {
//
////        1获取额度 2只更新学信 3直接进入借钱
//        if (item.data.sta.equals("3")) {
//            PreferenceUtils.putString(getActivity(), "type_id", loanTypeId + "");
//            api.getNewBeginApply(loanTypeId);
//            return;
//        }
//        showLoading(false);
//        if (item.data.sta.equals("1") || item.data.sta.equals("2")) {
//            Dialog.showDefaultDialog(getActivity(), "提示", item.data.alert, "", "确认", false, new Dialog.DialogDefaultClickListener() {
//                @Override
//                public void confirm() {
//                    Intent intent = new Intent(getActivity(), Idcardv2Activity.class);
//                    intent.putExtra(Const.KEY.DEAL_BEFORE, item);
//                    startActivity(intent);
//                    getActivity().overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//                }
//
//                @Override
//                public void cancel() {
//
//                }
//            });
//        }
//    }
//
//    @OnClick({R.id.btn_apply, R.id.txt_agree})
//    public void onViewClicked(View view) {
//        if (UI.isFastClick()) {
//            return;
//        }
//        switch (view.getId()) {
//            case R.id.btn_apply:
//                if (!PreferenceUtils.getBoolean(getActivity(), "is_logined", false)) {
//                    Util.startActivity(getActivity(), V3LoginByCodeActivity.class);
//                } else {
//                    if (!cbAgree.isChecked()) {
//                        ToastUtil.makeText(getActivity(), "请勾选同意协议").show();
//                        return;
//                    }
//                    api.getDealBefore();
//                }
//                break;
//            case R.id.txt_agree:
//                ((SelectMoneyActivity) getActivity()).showDialog();
//                break;
//        }
//
//    }
//}
